package com.anstudio.busfetion;

import com.mobclick.android.MobclickAgent;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ProgressBar;

public class BusFetionActivity extends Activity {
	private ProgressBar mProgressBar;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MobclickAgent.update(this);
        setContentView(R.layout.main);
        mProgressBar = (ProgressBar) findViewById(R.id.launcher_progress);
        loadingProgress();
    }
    
    
    @Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		MobclickAgent.onResume(this);
	}


	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		MobclickAgent.onPause(this);
	}


	private void loadingProgress(){
	    AsyncTask<Void, Void, Void> launchTask = new AsyncTask<Void, Void, Void>(){
	
	        @Override
			protected void onPreExecute() {
				// TODO Auto-generated method stub
				super.onPreExecute();
				mProgressBar.incrementProgressBy(20);
			}

			@Override
	        protected Void doInBackground(Void... params) {
	            // TODO Auto-generated method stub
	            try {
	                Thread.sleep(1000);
	            } catch (InterruptedException e) {
	                // TODO Auto-generated catch block
	                e.printStackTrace();
	            }
	            return null;
	        }
	
	        @Override
	        protected void onPostExecute(Void result) {
	            // TODO Auto-generated method stub
	            super.onPostExecute(result);
	            if(mProgressBar.getProgress()==100){
	            	launchActivity();
	            }else{
	            	loadingProgress();
	            }
	        }
	    };
	    launchTask.execute();
    }
    
    private void launchActivity(){
    	MainActivity.launch(BusFetionActivity.this);
        finish();
    }
}